#include "fsxsimconnectqtfier.h"
using namespace FsxSimConnect;

//
// Resolve enum id to string
// http://labs.qt.nokia.com/2008/10/09/coding-tip-pretty-printing-enum-values/
//
const QString FSXSimConnectQtfier::resolveEnumToString(const DWORD id, const char* enumName) {
    int i= FSXSimConnectQtfier::staticMetaObject.indexOfEnumerator(enumName);
    if (i < 0) return QString("No enumerator for %1").arg(enumName);
    QMetaEnum m = FSXSimConnectQtfier::staticMetaObject.enumerator(i);
    const char* k = m.valueToKey(id);
    return (k) ? QLatin1String(k) : QString("Id %1 not found for %2").arg(id).arg(enumName);
}

//
// Exception id to something human readible
//
const QString FSXSimConnectQtfier::simConnectExceptionToString(const DWORD id) {
    return FSXSimConnectQtfier::resolveEnumToString(id, "SIMCONNECT_EXCEPTION");
}

//
// The surface types
//
const QString FSXSimConnectQtfier::simConnectSurfaceTypeToString(const DWORD type, bool beautify)
{
    QString sf = FSXSimConnectQtfier::resolveEnumToString(type, "SIMCONNECT_SURFACE");
    return beautify ? sf.replace('_', ' ') : sf;
}
